<?php

/**
 * JMy97DatePicker class file.
 *
 * @author jerry2801 <jerry2801@gmail.com>
 * @version alpha 3 (2010-6-7 14:47)
 *
 * A typical usage of JMy97DatePicker is as follows:
 * <pre>
 * $this->widget('ext.my97DatePicker.JMy97DatePicker',array(
 *     'name'=>CHtml::activeName($model,'sendStartDateToForm'),
 *     'value'=>$model->sendStartDateToForm,
 *     'options'=>array('dateFmt'=>'yyyy-MM-dd'),
 * ));
 * </pre>
 */

Yii::import('zii.widgets.jui.CJuiInputWidget');

class SDateRange extends CJuiInputWidget
{
    public function init()
    {
        $path=dirname(__FILE__).DIRECTORY_SEPARATOR.'source';
        $baseUrl=Yii::app()->getAssetManager()->publish($path);
        //$baseUrl=Yii::app()->getAssetManager()->publish($path.'/css');
        $js=Yii::app()->getClientScript();
        $js->registerScriptFile($baseUrl.'/js/daterangepicker.jQuery.js');
        $js->registerScriptFile($baseUrl.'/js/jquery-ui-1.7.1.custom.min.js');
      	$js->registerCssFile($baseUrl.'/css/ui.daterangepicker.css');
      	$js->registerCssFile($baseUrl.'/css/redmond/jquery-ui-1.7.1.custom.css');
		//$js->registerScriptFile($baseUrl.'/widget.js');
		$js->registerCssFile($baseUrl.'/widget.css');
		
		$options=CJavaScript::jsonEncode($this->options);
		
        //echo $options;
        //$this->htmlOptions['onfocus']=strtr('daterangepicker({options});',array('{options}'=>$options));
        $this->htmlOptions['id']='rangeA';
		if($this->hasModel())
			echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);
		else
        {
            list($name,$id)=$this->resolveNameID();
			echo CHtml::textField($name,$this->value,$this->htmlOptions);
        }
        
        echo "<script >
			
		 $(function(){
			
			
			$(\"#rangeA\").daterangepicker(".$options.");
		});
		</script>";
		
        
    }
}